import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Test;

public class TextBuddyTest {
	
	
	// Test for sorting
	@Test
	public void test1() throws IOException {
		assertEquals("add", "added to test.txt: \"donut\"", TextBuddy.testCommand("add donut"));
		assertEquals("add", "added to test.txt: \"apple\"", TextBuddy.testCommand("add apple"));
		assertEquals("add", "added to test.txt: \"carrot\"", TextBuddy.testCommand("add carrot"));
		assertEquals("add", "added to test.txt: \"banana\"", TextBuddy.testCommand("add banana"));
		assertEquals("display unsorted", "1. donut\n2. apple\n3. carrot\n4. banana\n", TextBuddy.testCommand("display"));
		assertEquals("sort", "test.txt has been sorted", TextBuddy.testCommand("sort"));
		assertEquals("display sorted", "1. apple\n2. banana\n3. carrot\n4. donut\n", TextBuddy.testCommand("display"));
		assertEquals("add", "added to test.txt: \"elephant\"", TextBuddy.testCommand("add elephant"));
		assertEquals("add", "added to test.txt: \"ant\"", TextBuddy.testCommand("add ant"));
		assertEquals("display unsorted", "1. apple\n2. banana\n3. carrot\n4. donut\n5. elephant\n6. ant\n", TextBuddy.testCommand("display"));
		assertEquals("sort", "test.txt has been sorted", TextBuddy.testCommand("sort"));
		assertEquals("display sorted", "1. ant\n2. apple\n3. banana\n4. carrot\n5. donut\n6. elephant\n", TextBuddy.testCommand("display"));
		assertEquals("clear", "all content deleted from test.txt", TextBuddy.testCommand("clear"));
	}
	
	// Test for searching
	@Test
	public void test2() throws IOException {
		assertEquals("add", "added to test.txt: \"donut\"", TextBuddy.testCommand("add donut"));
		assertEquals("add", "added to test.txt: \"apple\"", TextBuddy.testCommand("add apple"));
		assertEquals("add", "added to test.txt: \"carrot\"", TextBuddy.testCommand("add carrot"));
		assertEquals("add", "added to test.txt: \"banana\"", TextBuddy.testCommand("add banana"));
		assertEquals("search", "\"elephant\" is not found in test.txt", TextBuddy.testCommand("search elephant"));
		assertEquals("search", "search found: 3. carrot", TextBuddy.testCommand("search carrot"));
		assertEquals("search", "search found: 1. donut", TextBuddy.testCommand("search donut"));
		assertEquals("search", "search found: 4. banana", TextBuddy.testCommand("search banana"));
	}
	
	// Clear the document
	@Test
	public void test3() throws IOException {
		assertEquals("clear", "all content deleted from test.txt", TextBuddy.testCommand("clear"));
	}
	
}
